package com.magina.project.mgdb.service.impl;

import com.google.common.eventbus.EventBus;
import com.magina.project.mgdb.event.DemoEvent1;
import com.magina.project.mgdb.listencer.MaginaListener;
import com.magina.project.mgdb.service.EventBusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassnName :com.magina.project.mgdb.demo.sysuser.service.impl.EventBusService
 * @Author： Magina.Hu
 * @Date： 2019/5/6
 * @Description：
 * @Version: V1.0
 * Copyright (c) 2019-2020 .All rights reserved.
 */

@Service
public class EventBusServiceImpl implements EventBusService {

    @Autowired
    private MaginaListener maginaListener ;

    @Autowired
    private EventBus eventBus ;

    @Autowired
    private EventBus asyncEventBus ;

    @Override
    public void postEvent(){
        eventBus.register(maginaListener);
        eventBus.post(new DemoEvent1("magina","123456"));
    }

    @Override
    public void asyncPostEvent(){
        asyncEventBus.register(maginaListener);
        asyncEventBus.post(new DemoEvent1("magina_async","123456"));
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        asyncEventBus.register(maginaListener);
        eventBus.register(maginaListener);
    }
}